package cn.lavender.crypto.symmetry;


import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.DES;
import org.apache.tomcat.util.codec.binary.Base64;

/**
 * <p>
 * 对称算法：DES
 * </p>
 *
 * @author: zhu.chen
 * @date: 2021/3/20
 * @version: v1.0.0
 */
public class DesCrypto {

    private static final DES DES = SecureUtil.des();

    /**
     * 加密
     * @param data
     * @return
     */
    public static String encrypt(String data) {
        return Base64.encodeBase64String(DES.encrypt(data));
    }


    /**
     * 解密
     * @param cipher
     * @return
     */
    public static String decrypt(String cipher) {
        return new String(DES.decrypt(Base64.decodeBase64(cipher)));
    }

    public static void main(String[] args) {
        String cipher = DesCrypto.encrypt("小明");
        System.out.println(cipher);
        System.out.println(DesCrypto.decrypt(cipher));
    }


}
